<template>
    <view style="padding: 15px;">
        <u-form ref="validateFormRef" :model="validateForm.value" :label-width="150">
            <u-form-item label="登录账号" prop="username" required>
                <u-input v-model="validateForm.value.username" placeholder="请输入登录账号"/>
            </u-form-item>
        </u-form>

        <u-button type="error" @click="submit">下一步</u-button>
    </view>
</template>

<script>

    import {CommonService} from "../../../../dev/services/common.service";

    export default {
        data() {
            return {
                validateForm: {
                    value: {
                        username: '',
                    },
                    rules: {
                        username: [
                            {required: true, message: '必填项!', trigger: ['change', 'blur']},
                            {pattern: /^(?=.*\S).+$/, message: '必填项!', trigger: ['change', 'blur']},
                            {
                                trigger: ['blur'],
                                asyncValidator: (rule, value, callback) => {
                                    new CommonService().uniqueCheckByFields({
                                        'tableName': 'sys_user',
                                        'fieldList': [
                                            {'fieldName': 'username', 'fieldValue': value}
                                        ],
                                        'excludeId': null
                                    }).then(result => {
                                        if (result.status === "fail") {
                                            callback();
                                        } else {
                                            callback(new Error('登录账号不存在！'));
                                        }
                                    });
                                }
                            }
                        ],
                    }
                }
            }
        },
        onReady() {
            const _self = this
        },
        methods: {
            submit() {
                const _self = this;
                this.$refs.validateFormRef.validate(valid => {
                    if (valid) {
                        console.log('验证通过', _self.validateForm.value);
                        _self.navigateTo(`/pages/main/login/forget-password/forget-password-update-password/index?username=${_self.validateForm.value.username}`);
                    } else {
                        console.log('验证失败');
                    }
                });
            }
        }
    }
</script>

<style lang="scss" scoped>
</style>
